package org.springcloud.wisdom.springcloud_03_freshman.admin.controller;

import org.springcloud.wisdom.springcloud_03_freshman.admin.entity.Notice;
import org.springcloud.wisdom.springcloud_03_freshman.admin.service.NoticeService;
import org.springcloud.wisdom.springcloud_03_freshman.common.bean.ResponseData;
import org.springcloud.wisdom.springcloud_03_freshman.common.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class NoticeController extends BaseController {
    @Autowired
    NoticeService noticeService;

    /**
     * 公告审核通过
     * @param id
     * @return
     */
    @GetMapping("/admin/approve")
    public ResponseData<Boolean> approve(@RequestParam("id")Integer id){
        Notice notice=noticeService.getNotice(id);
        return  returnObject(noticeService.approveNotice(notice));
    }

    /**
     * 公告审核拒绝
     * @param id
     * @return
     */
    @GetMapping("/admin/reject")
    public ResponseData<Boolean> reject(@RequestParam("id")Integer id){
        Notice notice=noticeService.getNotice(id);
        return  returnObject(noticeService.rejectNotice(notice));
    }

    /**
     * 发布公告
     * @param notice
     * @return
     */
    @PostMapping("/notice/add")
    public ResponseData<Boolean> addNotice(Notice notice){
        System.out.println(notice);
        return returnObject(noticeService.addNotice(notice));
    }

    /**
     * 删除公告
     * @param id
     * @return
     */
    @DeleteMapping("/admin/delete/{id}")
    public ResponseData<Boolean> delete(@PathVariable("id") Integer id){
        return returnBoolean(noticeService.deleteNotice(id));
    }

    @GetMapping("/notice/all")
    public ResponseData<Object> get(
            @RequestParam("pageNum") int pageNum,
            @RequestParam("pageSize")int pageSize,
            @RequestParam(value = "ispublic",required = false)String ispublic,
            @RequestParam(value = "type",required = false)Integer type,
            @RequestParam(value = "orderBy",required = false)Integer orderBy
    ){
        return returnObject(noticeService.getNoticePage(pageNum, pageSize, ispublic, type,orderBy));
    }
    @DeleteMapping("/notice/dels")
    public  ResponseData<Boolean> dels(@RequestParam("id") List<Integer> ids){
        return  returnBoolean(noticeService.delNoticeIds(ids));
    }
}
